import pymysql

# 连接数据库
connection = pymysql.connect(host='localhost',   # 数据库地址
                             user='root',        # 用户名
                             password='xxxxxxxx',  # 密码
                             database='iphone',  # 数据库名
                             port=3306)                 # 端口

# 创建游标对象
cursor = connection.cursor()

# 执行SQL语句
cursor.execute("SELECT * FROM 通讯录")

# 获取查询结果
results = cursor.fetchall()
for row in results:
    print(row)

# 关闭游标和连接
cursor.close()
connection.close()
